<!DOCTYPE html>
<html lang="en">

<head>
    <!-- /static/Admin/ -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <link rel="stylesheet" type="text/css" href="/static/Admin/plugins/colorpicker/colorpicker.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/custom-plugins/wizard/wizard.css" media="screen">

    <!-- Required Stylesheets -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/bootstrap/css/bootstrap.min.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/fonts/ptsans/stylesheet.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/fonts/icomoon/style.css" media="screen">

    <link rel="stylesheet" type="text/css" href="/static/Admin/css/mws-style.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/icons/icol16.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/icons/icol32.css" media="screen">

    <!-- Demo Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/demo.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/menu.css" media="screen">

    <!-- jQuery-UI Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/jui/css/jquery.ui.all.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/jui/jquery-ui.custom.css" media="screen">

    <!-- Theme Stylesheet -->
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/mws-theme.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/static/Admin/css/themer.css" media="screen">
</head>

<body>

    <div id="mws-wrapper">
    
        
        <div id="mws-sidebar">
    
            
            
    
            <!-- Main Navigation -->
            <div id="mws-navigation">
                <ul>
                    <li class="active">
                        <a href="/content" target="right_content">
                            <i class="icon-home"></i> 后台首页</a>
                    </li>
                    {if condition="in_array('goods',$rightList)"}
                    <li>
                        <a href="#">
                            <i class="icon-list"></i> 商品管理</a>
                        <ul class="">

                            <li>
                                <a href="/goods/GoodsCateList" target="right_content">商品分类</a>
                            </li>
                            <li>
                                <a href="/goods/GoodsList" target="right_content">查看全部商品</a>
                            </li>
                            <li>
                                <a href="/goods/AddGoods" target="right_content">添加商品</a>
                            </li>
                            
                        </ul>
                    </li>
                    <li>
                        <a href="#">
                            <i class="icon-list"></i>电池管理</a>
                        <ul class="">

                            <li>
                                <a href="/battery/GoodsList" target="right_content">电池列表</a>
                            </li>
                            <li>
                                <a href="/battery/AddGoods" target="right_content">添加电池</a>
                            </li>

                        </ul>
                    </li>
                    {/if}
                     {if condition="in_array('order',$rightList)"}
                    <li class="badge-container">
                        <a href="#">
                            <i class="icon-list"></i> 订单管理 <span class="badge">
                             {php}$order_total_msg_num=0;if(!empty($notify_nums[31])) $order_total_msg_num+=$notify_nums[31];
                                if(!empty($notify_nums[231])) $order_total_msg_num+=$notify_nums[231];
                                 if(!empty($notify_nums[232])) $order_total_msg_num+=$notify_nums[232];
                            echo $order_total_msg_num;
                             {/php}</span></a>
                        <ul class="">
                            <li data-msg-type="31">
                                <a href="/order/OrderList" target="right_content">订单列表<span class="badge">{$notify_nums[31]|default=0}</span></a>
                            </li>
                            <li>
                                <!-- <a href="/order/UnsendOrderList/status/2" target="right_content">未发货订单列表</a> -->
                            </li>
                            <li data-msg-type="231">
                                <a href="/battery_order/OrderList" target="right_content">电池订单列表<span class="badge">{$notify_nums[231]|default=0}</span></a>
                            </li>
                            <li data-msg-type="232">
                                <a href="/battery_order/ApplyCancelOrderList" target="right_content">申请取消订单<span class="badge">{$notify_nums[232]|default=0}</span></a>
                            </li>
                        </ul>
                    </li>
                    <li class="badge-container">
                        <a href="#">
                            <i class="icon-list"></i> 提现管理</a>
                        <ul class="closed">
                            <li data-msg-type="13">
                                <a href="/withdraw/index" target="right_content">提现列表<span class="badge">{$notify_nums[13]|default=0}</span></a>
                            </li>

                        </ul>
                    </li>
                     {/if} {if condition="in_array('user',$rightList)"}
                    <li>
                        <a href="#" >
                            <i class="icon-list"></i> 用户管理</a>
                        <ul class="">
                            <li>
                                <a href="/user/UserList" target="right_content">客户列表</a>
                            </li>
                            
                        </ul>
                    </li>
                    <li >
                        <a href="#">
                            <i class="icon-list"></i> 积分管理</a>
                        <ul class="closed">
                            <li >
                                <a href="/points/index" target="right_content">积分记录</a>
                            </li>

                                <li >
                                    <a href="/invite/index" target="right_content">邀请记录</a>
                                </li>

                        </ul>
                    </li>

                     {/if} {if condition="in_array('announce',$rightList)"}
                    <li>
                        <a href="#">
                            <i class="icon-list"></i> 公告管理</a>
                        <ul class="">
                            <li>
                                <a href="/announce/BannerList" target="right_content">首页轮播图</a>
                            </li>
                            <li>
                                <a href="/announce/BannerAdd" target="right_content">添加Banner</a>
                            </li>
                            <!-- <li>
                                <a href="/announce/PushMsgList" target="right_content">已推送通知消息列表</a>
                            </li> -->
                            <!-- <li>
                                <a href="/announce/DraftMsgList" target="right_content">草稿消息列表</a>
                            </li> -->
                            <!-- <li>
                                <a href="/announce/MsgAdd" target="right_content">新建推送消息</a>
                            </li> -->

                        </ul>
                    </li>
                    <li >
                        <a href="#">
                            <i class="icon-list"></i> 电池Banner</a>
                        <ul class="closed">
                            <li >
                                <a href="/battery_banner/bannerList" target="right_content">Banner列表</a>
                            </li>


                        </ul>
                    </li>
                     {/if} {if condition="in_array('coupon',$rightList)"}
                    <li>
                        <a href="#">
                            <i class="icon-list"></i> 优惠券管理</a>
                        <ul class="closed">
                            <li>
                                <a href="/Coupon/CouponList" target="right_content">优惠券列表</a>
                            </li>
                            <li>
                                <a href="/Coupon/CouponAdd" target="right_content">自定义优惠券</a>
                            </li>
                            <!-- <li>
                                <a href="form_wizard.html" target="right_content">Wizard</a>
                            </li> -->
                        </ul>
                    </li>
                     {/if} {if condition="in_array('admin',$rightList)"}
                    <li>
                        <a href="#">
                            <i class="icon-list"></i> 后台管理员</a>
                        <ul class="">
                            <li>
                                <a href="/admin/AdminList" target="right_content">查看全部管理员</a>
                            </li>
                            <li>
                                <a href="/admin/AdminAdd" target="right_content">添加管理员</a>
                            </li>
                        </ul>
                    </li>
                     {/if} 
                </ul>
            </div>
        </div>
    </div>    
    

    <!-- JavaScript Plugins -->
    <script src="/static/Admin/js/libs/jquery-1.8.3.min.js"></script>
    <script src="/static/Admin/js/libs/jquery.mousewheel.min.js"></script>
    <script src="/static/Admin/js/libs/jquery.placeholder.min.js"></script>
    <script src="/static/Admin/custom-plugins/fileinput.js"></script>

    <!-- jQuery-UI Dependent Scripts -->
    <script src="/static/Admin/jui/js/jquery-ui-1.9.2.min.js"></script>
    <script src="/static/Admin/jui/jquery-ui.custom.min.js"></script>
    <script src="/static/Admin/jui/js/jquery.ui.touch-punch.js"></script>

    <!-- Plugin Scripts -->
    <script src="/static/Admin/plugins/datatables/jquery.dataTables.min.js"></script>
    <!--[if lt IE 9]>
        <script src="js/libs/excanvas.min.js"></script>
        <![endif]-->
    <script src="/static/Admin/plugins/flot/jquery.flot.min.js"></script>
    <script src="/static/Admin/plugins/flot/plugins/jquery.flot.tooltip.min.js"></script>
    <script src="/static/Admin/plugins/flot/plugins/jquery.flot.pie.min.js"></script>
    <script src="/static/Admin/plugins/flot/plugins/jquery.flot.stack.min.js"></script>
    <script src="/static/Admin/plugins/flot/plugins/jquery.flot.resize.min.js"></script>
    <script src="/static/Admin/plugins/colorpicker/colorpicker-min.js"></script>
    <script src="/static/Admin/plugins/validate/jquery.validate-min.js"></script>
    <script src="/static/Admin/custom-plugins/wizard/wizard.min.js"></script>

    <!-- Core Script -->
    <script src="/static/Admin/bootstrap/js/bootstrap.min.js"></script>
    <script src="/static/Admin/js/core/mws.js"></script>

    <!-- Themer Script (Remove if not needed) -->
    <script src="/static/Admin/js/core/themer.js"></script>

    <!-- Demo Scripts (remove if not needed) -->
    <script src="/static/Admin/js/demo/demo.dashboard.js"></script>
<script type="application/javascript">
    function markMsg(msg){

        var $target = $("[data-msg-type="+msg.notify_type+"] .badge");
        var value = parseInt($target.text());
        // 父节点 ；
        var $parentBadge = $target.closest(".badge-container").find(">a .badge");
        var totalValue2  = parseInt( $parentBadge.text() );
        //加一
        if(msg.op=="add"){
            $target.text(value+1);
            $target.show();
            $parentBadge.text(totalValue2+1);
            $parentBadge.show();
        }else{
            //减一
            if(value>0){
                value-=1;
                $target.text(value);
                if(value==0){
                    $target.hide();
                }
            }
            if(totalValue2>0){
                totalValue2-=1;
                $parentBadge.text(totalValue2);
                if(totalValue2==0){
                    $parentBadge.hide();
                }
            }

        }

    }

    // 初始化未读消息的标记，如果是0，就不显示
    $("[data-msg-type]").each(function(i,e){
        var $this = $(this);
        var $badge =$this.find(".badge");
        var value = parseInt($badge.text());

        if(!value || value < 1){
            $badge.hide();
            // debugger
            $this.closest(".badge-container").find(">a .badge").hide();
        }
    });


    /*点击时，清除掉自身的未读消息数，并更新父元素的未读消息数*/
    $("[data-msg-type]").click(function(){
        var $this = $(this);
        var $badge =$this.find(".badge");
        var value = parseInt($badge.text());
        $badge.text(0).hide();

        var $parentBadge = $this.closest(".badge-container").find(">a .badge");
        var totalValue2  = parseInt( $parentBadge.text() );
        $parentBadge.text(totalValue2-value);
        if(totalValue2-value <= 0){
            $parentBadge.hide();
        }

        //清除通知数
        if(value > 0){
            var notifyType=$this.attr('data-msg-type');
            $.post("__WebSite__/Admin/ajaxClearNotifyNum",{notify_type:notifyType},function (data) {
            },'json');
        }

    });

    //var wsServer = 'ws://admin.zjhzzdh.cn:9506?client_type=admin_notify';
    var wsServer = 'ws://192.168.1.190:9506?client_type=admin_notify';
    var websocket = new WebSocket(wsServer);
    websocket.onopen = function (evt) {
        console.log("Connected to WebSocket server.");
    };

    websocket.onclose = function (evt) {
        console.log("Disconnected");
    };

    websocket.onmessage = function (evt) {
        console.log('Retrieved data from server: ' + evt.data);


        markMsg(JSON.parse(evt.data));


        // {"type":"admin_notify_num","op":"sub","notify_type":"23","auth":"0e541bf02aab56ce6e7e8c3dfae7f77a"}
    };

    websocket.onerror = function (evt, e) {
        console.log('Error occured: ' + evt.data);
    };
</script>
</body>

</html>